package org.video.mine.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import org.video.mine.R;
import org.video.mine.databinding.HistoryLayoutBinding;
import org.video.mine.databinding.MovieInfoBinding;
import org.video.mine.databinding.MovieInfoNameBinding;
import org.video.mine.entity.LookHistoryEntity;
import org.video.mine.entity.MovieInfoEntity;
import org.video.mine.model.ClickModel;

import java.util.List;

public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHolder> {

    List<LookHistoryEntity> historyEntities;
    Context context;

    public HistoryAdapter(List<LookHistoryEntity> titleEntities, Context context) {
        this.historyEntities = titleEntities;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding binding;
        binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.history_layout, parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ((HistoryLayoutBinding)holder.getTitleBinding()).setHistory(historyEntities.get(position));
        ((HistoryLayoutBinding)holder.getTitleBinding()).setClick(new ClickModel());
        ((HistoryLayoutBinding)holder.getTitleBinding()).setContext(context);
    }

    @Override
    public int getItemCount() {
        return historyEntities.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        ViewDataBinding titleBinding = null;

        public ViewHolder(ViewDataBinding titleBinding) {
            super(titleBinding.getRoot());
            this.titleBinding = titleBinding;
        }

        public ViewDataBinding getTitleBinding(){
            return titleBinding;
        }
    }
}
